//
//  ZQComposePhotosView.m
//  柳州微博
//
//  Created by Apple_Lzzy45 on 16/11/9.
//  Copyright © 2016年 Apple_Lzzy40. All rights reserved.
//

#import "ZQComposePhotosView.h"

@implementation ZQComposePhotosView

-(instancetype)initWithFrame:(CGRect)frame
{

    self =[super initWithFrame:frame];
    if (self) {
        _photos =[NSMutableArray array];
    }
    return self;
}
-(void)addPhoto:(UIImage *)photo
{
    UIImageView * photoView =[[UIImageView alloc]init];
    photoView.image = photo;
    [self addSubview:photoView];
    [self.photos addObject:photo];
}
-(void)layoutSubviews
{
    [super layoutSubviews];
    CGFloat imageMargin = 9;
    CGFloat imageWH = 70;
    int maxCols = 4;
    NSUInteger count = self.subviews.count;
    //遍历所有图片控件 设置frame
    for (int i =0; i<count; i++) {
        UIImageView *photoView =self.subviews[i];
        int col =i%maxCols;
        photoView.x=col*(imageWH+imageMargin)+imageMargin;
        
        int row =i/maxCols;
        photoView.y=row*(imageWH+imageMargin)+imageMargin;
        photoView.width=imageWH;
        photoView.height=imageWH;
        
    }
}
@end
